package org.jeecg.modules.purchase.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.purchase.entity.PurchaseHelloEntity;
import org.jeecg.modules.purchase.service.IPurchaseHelloService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletRequest;

@Api(tags = "purchase示例")
@RestController
@RequestMapping("/purchase")
@Slf4j
public class PurchaseHelloController {

	@Autowired
	private IPurchaseHelloService jeecgHelloService;

	@ApiOperation(value = "hello", notes = "对外服务接口")
	@GetMapping(value = "/hello")
	public String sayHello() {
		log.info(" ---我被调用了--- ");
		return jeecgHelloService.hello();
	}

	@ApiOperation(value = "getCurrentUser", notes = "获取当前登录用户信息")
	@GetMapping(value = "/getCurrentUser")
	public LoginUser getCurrentUser(){
		LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
		return sysUser;
	}

	@ApiOperation(value = "getTenantId", notes = "获取当前租户信息")
	@GetMapping(value = "/getTenantId")
	public String getTenantId(HttpServletRequest request){
		String tenantId = request.getHeader("tenant-id");
		return tenantId;
	}
	@ApiOperation(value = "getToken", notes = "获取当前token认证信息")
	@GetMapping(value = "/getToken")
	public String getToken(HttpServletRequest request){
		String token = request.getHeader("X-Access-Token");
		return token;
	}

}
